package com.nciae.chain.handler.score;

import com.nciae.po.HousemasterSocre;
import com.nciae.po.Score;
import com.nciae.service.IHoursemasterService;
import com.nciae.service.IHousemasterSocreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
@Order(1)
public class HourseMasterScoreHandler implements SHandler{

    @Autowired
    private IHoursemasterService hoursemasterService;

    @Autowired
    private IHousemasterSocreService housemasterSocreService;


    @Override
    public void service(Score score, int option) {

        if (option == 1) {
            HousemasterSocre housemasterSocre = new HousemasterSocre();
            housemasterSocre.setHousemasterId(score.getHoursemaster().getId());
            housemasterSocre.setScoreId(score.getId());
            housemasterSocreService.add(housemasterSocre);
        }

        if (option == 2) {
            List<HousemasterSocre> housemasterSocres = new ArrayList<>();
            for(HousemasterSocre housemasterSocre : housemasterSocres) {
                score.setHoursemaster(hoursemasterService.findHoursemasterById(housemasterSocre.getHousemasterId()));
            }
        }
    }
}
